package com.bnlr.lrparking.widget;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.bnlr.lrparking.R;
import com.bnlr.lrparking.appui.login.ForgetPassWordActivity;
import com.bnlr.lrparking.effects.BaseEffects;
import com.bnlr.lrparking.effects.Effectstype;

/**
 * Created by Administrator on 2017/6/6.
 */

public class LoginPsdDialog extends Dialog {
    private Context context;
    public LoginPsdDialog(Context context) {
        super(context, R.style.NativeDialog);
        this.context = context;
        initView();
    }
    View mView;
    ImageView close;
    TextView tv_tologin,tv_misspsw;
    Effectstype type;
    private void initView() {
        mView= LayoutInflater.from(getContext()).inflate(R.layout.doalog_login02, null);
        close= (ImageView) mView.findViewById(R.id.img_close);
        tv_tologin= (TextView) mView.findViewById(R.id.tv_tophone_login);
        tv_misspsw= (TextView) mView.findViewById(R.id.tv_login_miss_pwd);
        tv_misspsw.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LoginPsdDialog.this.dismiss();
                Intent intent=new Intent(context, ForgetPassWordActivity.class);
                context.startActivity(intent);
            }
        });
        tv_tologin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LoginPsdDialog.this.dismiss();
                LoginDialog LoginDialog = new LoginDialog(context);
                LoginDialog.show();
            }
        });
        close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LoginPsdDialog.this.dismiss();
            }
        });
        this.setOnShowListener(new OnShowListener() {
            @Override
            public void onShow(DialogInterface dialogInterface) {
                type = Effectstype.FlipR;
                mView.setVisibility(View.VISIBLE);
                BaseEffects animator = type.getAnimator();
                animator.setDuration(Math.abs(500));
                animator.start(mView);

            }
        });
        super.setContentView(mView);
    }
    @Override
    public void setContentView(int layoutResID) {
    }

    @Override
    public void setContentView(@NonNull View view, ViewGroup.LayoutParams params) {
    }

    @Override
    public void setContentView(@NonNull View view) {
    }
    @Override
    public void show() {
        super.show();
        Window dialogWindow = this.getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        // 获取屏幕宽度
        DisplayMetrics dm = new DisplayMetrics();
        WindowManager wm = (WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE);;
        wm.getDefaultDisplay().getMetrics(dm);
        int screenWidth = dm.widthPixels;
        // 设置宽度
        lp.width = (int) (screenWidth * 0.85);
        dialogWindow.setAttributes(lp);
    }
}
